package com.filter;

import com.bean.BhRole;
import com.bean.BhUser;

import javax.servlet.*;
import javax.servlet.Filter;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

//@WebFilter({"/GoBhSy/*"})
//public class BhSyTeacherFilter implements javax.servlet.Filter{
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        System.out.println(request.getRequestURI()+"----正在过滤");
//        HttpSession session = request.getSession();
//        servletRequest.setCharacterEncoding("UTF-8");
//        servletResponse.setCharacterEncoding("UTF-8");
//        request.setCharacterEncoding("UTF-8");
//        response.setCharacterEncoding("UTF-8");
//        response.setContentType("text/html");
//        String url= request.getRequestURI();
//        BhUser bh = (BhUser) session.getAttribute("BhSyUser");
//        List<BhRole> br = (List<BhRole>) session.getAttribute("BhSyRole") ;
//        boolean flag = false;
//        if (bh==null||br==null){
//            response.sendRedirect("/BhSyCase/UserBhSy/openWeb?findU=BhSyCaseMain.jsp");
//            return;
//        }
//        for (int i = 0; i < br.size() ; i++) {
//            if (url.endsWith(br.get(i).getbUrl())){
//                flag = true;
//                break;
//            }else {
//                flag = false;
//            }
//        }
//        if (request.getRequestURI().endsWith("/GoBhSy/openWeb")&&bh.getuSystem()==2){
//            filterChain.doFilter(servletRequest,servletResponse);
//        }else {
//            response.sendRedirect("/BhSyCase/UserBhSy/openWeb?findU=BhSyCaseMain.jsp");
//            return;
//        }
//        if (flag){
//            filterChain.doFilter(servletRequest,servletResponse);
//        }else {
//            response.sendRedirect("/BhSyCase/UserBhSy/openWeb?findU=BhSyCaseMain.jsp");
//            return;
//        }
//    }

//    @Override
//    public void destroy() {
//
//    }
//}
